package com.bida.controller.admin;


import com.bida.domain.dto.DishDTO;
import com.bida.domain.dto.DishPageQueryDTO;
import com.bida.domain.po.Dish;
import com.bida.domain.vo.DishVO;
import com.bida.result.PageResult;
import com.bida.result.Result;
import com.bida.service.IDishService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 菜品 前端控制器
 * </p>
 *
 * @author ly
 * @since 2024-09-06
 */
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Resource
    private IDishService dishService;

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> getDishInfoPage(DishPageQueryDTO dishPageQueryDTO){
        return dishService.getDishInfoPage(dishPageQueryDTO);
    }

    /**
     * 新增菜品
     * @param dishDTO
     * @return
     */
    @PostMapping
    public Result insertDishInfo(@RequestBody DishDTO dishDTO){
        return dishService.insertDishInfo(dishDTO);
    }

    /**
     * 批量删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteDishInfoByIds(@RequestParam List<Long> ids){
        return dishService.deleteDishInfoByIds(ids);
    }

    /**
     * 修改菜品
     * @param dishDTO
     * @return
     */
    @PutMapping
    public Result updateDishInfo(@RequestBody DishDTO dishDTO){
        return dishService.updateDishInfo(dishDTO);
    }

    /**
     * 根据id获取菜品信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<DishVO> getDishInfoById(@PathVariable("id") Long id){
        return dishService.getDishInfoById(id);
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    public Result<List<Dish>> getDishListByCategoryId(Long categoryId){
        return dishService.getDishListByCategoryId(categoryId);
    }

    /**
     * 菜品起售、停售
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result updateStatusById(@PathVariable Integer status,Long id){
        return dishService.updateStatusById(status,id);
    }


}
